<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\yperp\admin;

use app\admin\controller\Admin;
use app\yperp\common\AmisController;
use app\yperp\model\GoodsSku;
use app\yperp\model\Supcorp;
use think\Db;
use app\common\builder\ZBuilder;
use app\yperp\model\Goods;
use app\yperp\model\GoodsSkuStandby;
use app\yperp\model\Supplier as SupplierModel;
use think\facade\View;

/**
 * 仪表盘控制器
 * @package app\yperp\admin
 */
class Index extends Admin
{
    use AmisController;
    /**
     * 首页
     * @author 蔡伟明 <314013107@qq.com>
     * @return mixed
     */
    public function index()
    {



        $ids = [
            "74195",
            "46713",
            "74196",
            "74201",
            "74185",
            "74184",
            "74147",
            "74159",
            "74157",
            "74144",
            "74152",
            "74150",
            "74142",
            "74139",
            "46723",
            "74156",
            "74154",
            "74148",
            "74146",
            "74138",
            "74205",
            "74207",
            "74206",
            "74208",
            "74167",
            "74166",
            "74165",
            "74161",
            "74160",
            "46673",
            "74164",
            "74163",
            "74162",
            "46739",
            "74209",
            "74211",
            "46730",
            "74210",
            "74186",
            "74190",
            "46729",
            "74191",
        ];




        foreach ($ids as $id) {
            $id = (int)$id;
            $goodsSku = GoodsSku::where(['id' => $id])->find();
            $check = GoodsSkuStandby::field('itemCode')->where('itemCode', $goodsSku['itemCode'])->find();
            if (!$check) {
                GoodsSkuStandby::saveGoods($goodsSku);
            } else {
                dump($goodsSku['itemName'] . '商品已存在');
            }
        }
















        die;
        if ($this->request->isPost()) {
            $param = $this->table->getFilterMap($this->request->post());

            $where = $param['map'];

            $GoodsSku = GoodsSku::whereIn('supplierId', $where['supplierId']);

            if ($where['supplyPriceS'] !== '' && $where['supplyPriceS'] !== '') {
                $GoodsSku->where('supplyPrice', 'between', [$where['supplyPriceS'], $where['supplyPriceE']]);
            }
            if ($where['itemName'] !== '') {
                $GoodsSku->whereLike('itemName', "%{$where['itemName']}%");
            }
            $data =  $GoodsSku->order('supplierId asc ,supplyPrice desc')->paginate();
            return AmisJson($data);
        }
        $Supcorp = Supcorp::column('supplierName', 'supplierId');
        $this->table
            ->addFilterItems([
                ['select', 'supplierId', '供应商', '请输入', $Supcorp],
                ['text', 'itemName', '商品名称', '请输入',],
                ['text', 'supplyPriceS', '供应价格开始', '请输入',],
                ['text', 'supplyPriceE', '供应价格结束', '请输入',],
            ])
            ->addColumns([ // 批量添加数据列
                ['id', 'ID'],
                ['pic', '规格图', 'img_url'],
                ['supplierId', '供应商', 'text', '', $Supcorp],
                ['itemName', '商品名称', 'text'],
                ['colour', '商品供应链ID', 'text'],
                ['itemCode', 'SKU编码', 'text'],
                ['supplyPrice', '供应价格', 'text'],
                ['spec', '尺寸', 'text'],
                ['weight', '重量', 'text'],
                ['linePrice', '分销控价', 'text'],
                ['dealPriceNinetyMax', '最高成交', 'text'],
                ['right_button', '操作', 'btn']
            ]);
        return $this->fetch_table(); // 渲染模板
    }
}
